﻿-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
use sms
go
if exists(select name from sysobjects where name ='cp_delete_nosend_reminder' and type = 'P')
drop procedure cp_delete_nosend_reminder
go  
-- =============================================
-- Author:		<Parker Zhou>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE cp_delete_nosend_reminder
	@email varchar(50), --input user's email
	--0 : normal
	--1 : no user
	--2 : inner exception
	@outs int output 
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	declare @userid int
	select @userid = UserID from [User] where [IsActive] = 1 and [Email] = @email
	--delete 
	if ( @userid > 0 )
		begin
			begin try
				delete from [Reminder] where [owner] = @userid and [send] = 0
				set @outs = 0
			end try
			begin catch
				set @outs = 2
			end catch
		end
	else
		begin
			set @outs = 1
		end
	
END
GO
